<template>
  <div>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
      <el-form-item label="姓名" prop="roleName">
        <el-input
          v-model="queryParams.roleName"
          placeholder="请输入"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证号" prop="roleName">
        <el-input
          v-model="queryParams.roleName"
          placeholder="请输入"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性别" prop="roleKey">
        <el-select v-model="queryParams.status" placeholder="请选择" clearable style="width: 240px">
          <el-option
            v-for="dict in dict.type.sys_normal_disable"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="工作单位" prop="roleKey">
        <el-select v-model="queryParams.status" placeholder="请选择" clearable style="width: 240px">
          <el-option
            v-for="dict in dict.type.sys_normal_disable"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
      <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
    </el-form>
    <el-table
      ref="table"
      @row-click="childrenData"
      v-loading="loading"
      :data="userList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="姓名" prop="userId" align="center" />
      <el-table-column label="性别" align="center" />
      <el-table-column label="身份证号" align="center" prop="dictId" />
      <el-table-column label="手机号" align="center" prop="dictName" :show-overflow-tooltip="true" />
      <el-table-column label="工作单位" align="违章处理" prop="dictName" :show-overflow-tooltip="true" />

      <el-table-column label="状态" align="center" prop="dictName" :show-overflow-tooltip="true" />

      <el-table-column label="户籍地址" align="center" prop="dictName" :show-overflow-tooltip="true" />
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="saveChaneTbale">保 存</el-button>
      <el-button @click="close">关 闭</el-button>
    </div>
  </div>
</template>
<script>
import {
  listUser,
  getUser,
  delUser,
  addUser,
  updateUser,
  resetUserPwd,
  changeUserStatus,
  deptTreeSelect
} from "@/api/system/user";
export default {
  dicts: ["sys_normal_disable", "sys_user_sex"],
  data() {
    return {
      userList: [],
      userList1: [],
      ids: [],
      // 总条数
      total: 0,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userName: undefined,
        phonenumber: undefined,
        status: undefined,
        deptId: undefined
      }
    };
  },
  created() {
    this.ids = [];
  },
  mounted() {
    this.getList();
    this.$refs["queryForm"].resetFields();
  },
  methods: {
    close() {
      this.$emit("close");
    },
    saveChaneTbale() {
      this.userList.map(res => {
        this.ids.map(resss => {
          if (res.userId == resss) {
            this.userList1.push(res);
          }
        });
      });

      this.userList1 = this.uniqueArray(this.userList1, "userId");
      console.log(this.userList1, "批量到处需要数据");
      this.close();

      //   this.open = false;
    },
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.userId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    uniqueArray(arr, key) {
      let list = [];
      return arr.filter(
        item => !list.includes(item.userId) && list.push(item.userId)
      );
    },
    childrenData(e) {
      console.log(e, "www");
    },
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      listUser(this.addDateRange(this.queryParams, this.dateRange)).then(
        response => {
          this.userList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    }
  }
};
</script>